/*
 * @Author: 杜二康 3224811364@qq.com
 * @Date: 2024-07-10 11:17:38
 * @LastEditors: 鏉滀簩搴� 3224811364@qq.com
 * @LastEditTime: 2024-07-10 14:13:17
 * @FilePath: src/service/user.ts
 * @Description: 用户登录接口
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */

import axios, {ResDataType} from "./ajax";

export async function getUserInfoService(): Promise<ResDataType> {
  const url = "/api/user/info";
  return (await axios.get(url)) as ResDataType;
}

export async function registerService(
  username: string,
  password: string,
  nickname?: string
): Promise<ResDataType> {
  const url = "/api/user/register";
  const body = {username, password, nickname: nickname || username};
  return (await axios.post(url, {body})) as ResDataType;
}

export async function loginService(
  username: string,
  password: string
): Promise<ResDataType> {
  const url = "/api/user/login";
  const body = {username, password};
  return (await axios.post(url, {body})) as ResDataType;
}
